<?php
//require_once ("C_krn_exception.php");
require_once ("web.class.php" );
require_once ("C_krn_tools.php" );

class c_HTML {
	
	/* Evitamos el clonaje del objeto. Patrón Singleton */
	private function __clone() {
	}
	private function __wakeup() {
	}
	private $BAR;
	private $HEADER;
	private $COLUMN_LEFT;
	private $CENTRAL;
	private $COLUMN_RIGHT;
	private $FOOTER;
	public function getBAR() {
		return $this->BAR;
	}
	public function getHEADER() {
		return $this->HEADER;
	}
	public function getCOLUMN_LEFT() {
		return $this->COLUMN_LEFT;
	}
	public function getCOLUMN_RIGHT() {
		return $this->COLUMN_RIGHT;
	}
	public function getFOOTER() {
		return $this->FOOTER;
	}
	public function getCENTRAL() {
		return $this->CENTRAL;
	}
	public function setHEADER($p) {
		global $IDIOMA, $language;
		
		$this->HEADER = '';
		$this->HEADER = $this->HEADER . ' <meta http-equiv="Content-Type" content="text/html; charset=utf-8">' . "\n";
		$this->HEADER = $this->HEADER . ' <meta name="viewport" content="width=device-width, initial-scale=1.0">' . "\n";
		$this->HEADER = $this->HEADER . ' <meta name="description" content="' . $language [$IDIOMA] [7] . '">' . "\n";
		$this->HEADER = $this->HEADER . ' <meta name="author" content="' . EMAIL_ADMIN . '">' . "\n";
		$this->HEADER = $this->HEADER . ' <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">' . "\n";
		
		$this->HEADER = $this->HEADER . ' <title>' . $language [$IDIOMA] [26] . ' v' . VERSION_HIGH . '.' . VERSION_LOW . '.' . VERSION_COMPILATION . ' - ' . $language [$IDIOMA] [7] .'</title>' . "\n";
		
		$this->HEADER = $this->HEADER . ' <link rel="shortcut icon" href="imarkket.ico" />' . "\n";
		
		// CARGAMOS CSS
		// Las imágenes del tema redmond de jquery-ui están en css/images/
		//$this->HEADER = $this->HEADER . ' <link rel="stylesheet" type="text/css" media="screen" href="css/jquery-ui-1.10.3.custom.css" />' . "\n";
		//$this->HEADER = $this->HEADER . ' <link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />' . "\n";
		
		$this->HEADER = $this->HEADER . ' <link rel="stylesheet" type="text/css" media="screen" href="css/style.css" />' . "\n";
		//$this->HEADER = $this->HEADER . ' <link rel="stylesheet" type="text/css" media="screen" href="css/style-menu.css" />' . "\n";
		$this->HEADER = $this->HEADER . ' <link rel="stylesheet" type="text/css" media="screen" href="css/style-sms.css" />' . "\n";
		$this->HEADER = $this->HEADER . ' <link rel="stylesheet" type="text/css" media="screen" href="css/bootstrap.css" />' . "\n";
		$this->HEADER = $this->HEADER . ' <link rel="stylesheet" type="text/css" media="screen" href="css/justified-nav.css" />' . "\n";

    // CSS para las tablas y pestañas de FooTable 
		$this->HEADER = $this->HEADER . ' <link rel="stylesheet" type="text/css" media="screen" href="css/footable-0.1.css" />' . "\n";
		$this->HEADER = $this->HEADER . ' <link rel="stylesheet" type="text/css" media="screen" href="css/footable.sortable-0.1.css" />' . "\n";
		$this->HEADER = $this->HEADER . ' <link rel="stylesheet" type="text/css" media="screen" href="css/bootstrap-responsive.css" />' . "\n";
		
		// CARGAMOS JS
		$this->HEADER = $this->HEADER . ' <script type="text/javascript" src="js/jquery-1.10.2.js"></script>' . "\n";
		$this->HEADER = $this->HEADER . ' <script type="text/javascript" src="js/bootstrap.js"></script>' . "\n";
		
		//$this->HEADER = $this->HEADER . ' <script type="text/javascript" src="js/jquery-ui-1.10.3.custom.js"></script>' . "\n";
		//$this->HEADER = $this->HEADER . ' <script type="text/javascript" src="js/grid.locale-es.js"></script>' . "\n";
		//$this->HEADER = $this->HEADER . ' <script type="text/javascript" src="js/jquery.jqGrid.js"></script>' . "\n";
		
		$this->HEADER = $this->HEADER . ' <script type="text/javascript" src="js/functions.external-sms.js"></script>' . "\n";
		$this->HEADER = $this->HEADER . ' <script type="text/javascript" src="js/functions.external.js"></script>' . "\n";
		
		$this->HEADER = $this->HEADER . ' <script type="text/javascript" src="js/functions.ajax.js"></script>' . "\n";
		
		// JS para las Tablas y pestañas de FooTable
		$this->HEADER = $this->HEADER . ' <script type="text/javascript" src="js/footable.js"></script>' . "\n";
		$this->HEADER = $this->HEADER . ' <script type="text/javascript" src="js/footable.sortable.js"></script>' . "\n";
		$this->HEADER = $this->HEADER . ' <script type="text/javascript" src="js/bootstrap-tab.js"></script>' . "\n";
		
		$this->HEADER = $this->HEADER . $p;
	}

	public function setBAR($pLOGIN) {
		global $cUTIL;
		global $s;
		global $IDIOMA, $language;

		$r = '';
			
    $r = $r . '  <div class="masthead">' . "\n";
    $r = $r . '      <h3 class="text-muted">' . APPLICATION_NAME . ' v' . VERSION_HIGH . '.' . VERSION_LOW . '.' . VERSION_COMPILATION . '</h3>' . "\n";
    $r = $r . '      <ul id="nav_ul" name="nav_ul" class="nav navbar-nav nav-justified">' . "\n";
    $r = $r . '        <li class="active" id="li_linkIndex" name="li_linkIndex"><a href="#" id="linkIndex" name="linkIndex" FORM_OPERATION="INDEX" CONNECT_MODE="' . $cUTIL->getDEVICE_TYPE ( $pNULL ) . '" >Home</a></li>' . "\n";
    
    if ($s->getEstaLogeado () && $s->esAdmin()) {
      $r = $r . '        <li id="li_linkAdmin" name="li_linkAdmin"><a href="#" id="linkAdmin" name="linkAdmin" FORM_OPERATION="INDEX_FORM_ADMIN" CONNECT_MODE="' . $cUTIL->getDEVICE_TYPE ( $pNULL ) . '" >'. $language [$IDIOMA] [78] .'</a></li>' . "\n";
    }
    $r = $r . '        <li id="li_linkAbout" name="li_linkAbout"><a href="#" id="linkAbout" name="linkAbout" FORM_OPERATION="INDEX_FORM_ABOUT" CONNECT_MODE="' . $cUTIL->getDEVICE_TYPE ( $pNULL ) . '" >'. $language [$IDIOMA] [82] .'</a></li>' . "\n";    
    $r = $r . '        <form class="navbar-form form-inline pull-right" name="FORM_LOGIN" id="FORM_LOGIN" FORM_OPERATION="FORM_LOGIN_AJ_JQ" CONNECT_MODE="' . $cUTIL->getDEVICE_TYPE ( $pNULL ) . '" method="POST" action="" accept-charset="UTF-8" >' . "\n";   
    // Si estoy logueado
    if (!$pLOGIN) { 
		  $r = $r . '				   <img   id="FORM_LOGIN_email_find"      name="FORM_LOGIN_email_find"     src="" />' . "\n";
      $r = $r . '          <input id="FORM_LOGIN_email"           name="FORM_LOGIN_email"          type="text" placeholder="Email">' . "\n";
      $r = $r . '				   <img   id="FORM_LOGIN_email_check"     name="FORM_LOGIN_email_check"    src="images/cross.png" />' . "\n";
		  $r = $r . '          <input id="FORM_LOGIN_password"        name="FORM_LOGIN_password"       type="password" placeholder="Password">' . "\n";
      $r = $r . '				   <img   id="FORM_LOGIN_password_check"  name="FORM_LOGIN_password_check" src="images/cross.png" />' . "\n";
	    $r = $r . '          <a     id="FORM_LOGIN_send"            name="FORM_LOGIN_send"            class="btn btn-small btn-success" href="#">'. $language [$IDIOMA] [28] .'</a>' . "\n";
    } else {
      $r = $r . '          <a id="FORM_LOGIN_logout" name="FORM_LOGIN_logout" FORM_OPERATION="FORM_LOGOUT" CONNECT_MODE="' . $cUTIL->getDEVICE_TYPE ( $pNULL) . '" class="btn btn-small btn-success" href="#">'. $language [$IDIOMA] [55] .'</a>' . "\n";
    }
    $r = $r . '        </form> ' . "\n";
    $r = $r . '      </ul>' . "\n";
    $r = $r . '    </div>' . "\n";
		
		/*
		
		if ($pLOGIN) {
			$p = $p . '	<li><a href="#">Herramientas</a>' . "\n";
			$p = $p . '		<ul>' . "\n";
			$p = $p . '			<li><a href="#" id="linkGestionUsuarios" name="linkGestionUsuarios" FORM_OPERATION="GESTION_USUARIOS" CONNECT_MODE="' . $cUTIL->getDEVICE_TYPE () . '">Gestión de Usuarios</a>' . "\n";
			$p = $p . '			</li>' . "\n";
			$p = $p . '		</ul>' . "\n";
			$p = $p . '	</li>' . "\n";
		}
		


		*/
		
		$this->BAR = $r;
	}
	
	public function setCENTRAL() {
		$this->CENTRAL = '';
		
		$r = '';
    $r = $r . '  <!-- CENTRO -->' . "\n";
    $r = $r . '  <!-- Jumbotron -->' . "\n";
    $r = $r . '  <div id="columncentral" name="columncentral"></div>' . "\n";
    $r = $r . '  <!-- FIN CENTRO -->' . "\n";
    
    // Dejo esto por ahora pero se debe quitar
    $r = $r . '' . "\n";
    $r = $r . '  <div class="body-content">' . "\n";
    $r = $r . '' . "\n";
    $r = $r . '    <!-- Example row of columns -->' . "\n";
    $r = $r . '    <div class="row">' . "\n";
    $r = $r . '      <div class="col-lg-4">' . "\n";
    $r = $r . '        <h2>Heading</h2>' . "\n";
    $r = $r . '        <p>Donec id elit non mi porta gravida at eget metusor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p>' . "\n";
    $r = $r . '        <p><a class="btn btn-default" href="#">View details &raquo;</a></p>' . "\n";
    $r = $r . '      </div>' . "\n";
    $r = $r . '      <div class="col-lg-4">' . "\n";
    $r = $r . '        <h2>Heading</h2>' . "\n";
    $r = $r . '        <p>Donec id elit non mi pac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p>' . "\n";
    $r = $r . '        <p><a class="btn btn-default" href="#">View details &raquo;</a></p>' . "\n";
    $r = $r . '     </div>' . "\n";
    $r = $r . '      <div class="col-lg-4">' . "\n";
    $r = $r . '        <h2>Heading</h2>' . "\n";
    $r = $r . '        <p>Donec sed odio dui. Cras eget quam. Vestibulum id ligula porta felis euismod semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa.</p>' . "\n";
    $r = $r . '        <p><a class="btn btn-default" href="#">View details &raquo;</a></p>' . "\n";
    $r = $r . '      </div>' . "\n";
    $r = $r . '    </div>' . "\n";
    $r = $r . '' . "\n";
    $r = $r . '  </div><!-- /.body-content -->' . "\n";
		
		$this->CENTRAL = $r;
	}
	
	public function setFOOTER($pFOOTER, $COUNTER) {
		global $cAUDIT;
		global $IDIOMA, $language;
		
	  $r = '';
	  
	  $r = $r . '  <!-- FOOTER -->' . "\n";
    $r = $r . '  <!-- Site footer -->' . "\n";
    $r = $r . '  <div class="footer">' . "\n";
    $r = $r . '    <p>' . "\n";
    $r = $r . '      &copy &reg ' . $language [$IDIOMA] [0] . ':' . $language [$IDIOMA] [100] . ' - <a href="http://creativecommons.org/licenses/by-nc-nd/3.0/deed.es_CO" id="link"><span>' . $language [$IDIOMA] [37] . '</span><em></em></a> - ' .  "\n";
    $r = $r . '      <a rel="license" href="' . $language [$IDIOMA] [27] . '">' . $language [$IDIOMA] [81] . '</a>' .  "\n";
	  
		// Si hay algo más se añade como parámetro
		if ($pFOOTER != '')
			$r = $r . ' - <a href="#" id="link">' . $pFOOTER . '</a> - ' . "\n";

    $r = $r . '    </p>' . "\n";    
    $r = $r . '    <p>' . "\n";
    $r = $r . '      <span class="text-center">' . $COUNTER . '</span>' . "\n";
    $r = $r . '    </p>' . "\n";    
    $r = $r . '  </div>' . "\n";
		
		$this->FOOTER = $r;
	}
	
	public function getHTML($pHEADER, $pCENTRAL, $pFOOTER, $pLOGIN, $COUNTER) {
		global $cAUDIT;
		global $IDIOMA, $language;
		global $cUTIL;
		
		$cAUDIT->AddAudit ( AUDIT_EXTEND, __DIR__, __FILE__, __LINE__, __CLASS__, __METHOD__, __FUNCTION__, $language [$IDIOMA] [67] );
		
		// Establecemos los valores de sus capas izq, dere y centro
		$this->setHEADER ( $pHEADER );
		$this->setBAR ( $pLOGIN );
		// Pasamos el valor de pLOGIN para saber si estoy o no logueado
		$this->setCENTRAL ();
		$this->setFOOTER ( $pFOOTER, $COUNTER );
		
		// Mostramos las capas
		$r = '';
		// HTML 5 - http://www.w3schools.com/tags/tag_doctype.asp
		//$r = $r . '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' . "\n";
		$r = $r . '<!DOCTYPE html>' . "\n";
		$r = $r . '<html xmlns="http://www.w3.org/1999/xhtml" lang="' . $language [$IDIOMA] [0] . '">' . "\n";
		$r = $r . '<head>' . "\n";
		$r = $r . $this->getHEADER ();
		$r = $r . '</head>' . "\n";
		$r = $r . '<body>' . "\n";
		$r = $r . ' <div class="container">' . "\n";
		$r = $r . $this->getBAR ();
		$r = $r . $this->getCENTRAL ();
		$r = $r . $this->getFOOTER ();
		$r = $r . ' </div> <!-- /container -->' . "\n";
		
		$r = $r . '</body>' . "\n";
		$r = $r . '</html>' . "\n";
		
		return $r;
	}
	function __construct($COUNTER) {
		global $cAUDIT;
		global $cUTIL;
		global $IDIOMA, $language;
		
		$cAUDIT->AddAudit ( AUDIT_EXTEND, __DIR__, __FILE__, __LINE__, __CLASS__, __METHOD__, __FUNCTION__, "::constructor (" . __CLASS__ . ")" );	
		$cAUDIT->AddAudit ( AUDIT_EXTEND, __DIR__, __FILE__, __LINE__, __CLASS__, __METHOD__, __FUNCTION__, $language [$IDIOMA] [25] );
		$cAUDIT->AddAudit ( AUDIT_EXTEND, __DIR__, __FILE__, __LINE__, __CLASS__, __METHOD__, __FUNCTION__, $language [$IDIOMA] [53] . $cUTIL->URL_Actual () );
		
		return true;
	}
	private static $_instance;
	public static function getInstance($COUNTER) {
		if (! (self::$_instance instanceof self)) {
			self::$_instance = new self ( $COUNTER );
		}
		return self::$_instance;
	}
}
;

// Instancia de la clase
try {
	$cHTML = c_HTML::getInstance ( $cUTIL->URL_Actual () );
	
} catch ( Exception $e ) {
	global $cAUDIT;
	global $IDIOMA, $language;
	$cAUDIT->AddAudit ( AUDIT_EXTEND, __DIR__, __FILE__, __LINE__, __CLASS__, __METHOD__, __FUNCTION__, $language [$IDIOMA] [2] . $e->getMessage () );
}

?>
